/* 封装axios 请求 */
import axios from 'axios'

import { Toast } from 'vant'

/* 新建axios 实例 */
const request = axios.create({
  baseURL: 'http://interview-api-t.itheima.net/h5/',
  timeout: 5000
})

/* 请求拦截器 */
request.interceptors.request.use(config => config, error => {
  return Promise.reject(error)
})

/* 响应拦截器 */

request.interceptors.response.use(response => response.data, error => {
  if (error) {
    console.log(error.response.data.message)
    Toast(error.response.data.message)
  }
  return Promise.reject(error)
})

export default request
